home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / emulation / tasread / tasread.bas < prev    next >
BASIC Source File  |  1999-06-14  |  8KB  |  286 lines

  1. REM ------------------------------
  2. REM TASREAD Tasword text formatter 
  3. REM Cut down from DOC2RTF: SNG/MJS
  4. REM ------------------------------
  5.  
  6. REM Originally for ZX82 files from XFS or SP_HANDLER
  7. REM Extended to read PLUS3DOS files from ZIPs or XFS
  8.  
  9. ' Works from Command Line or Workbench - expects ASL
  10. ' (WB2+ or PD versions) for Workbench file selector,
  11. ' but works without that, from the Amigados 1.3 CLI.
  12. '
  13. ' It should really trap the ASL library open failure
  14. ' and use simple INPUTs if running <= Workbench 1.3.
  15. '
  16. ' Workbench view is not yet properly font adaptive -
  17. ' text above 8 pitch overlaps progress indicator and
  18. ' may be too big for the window if average character
  19. ' width is more than eight pixels. Modified to use a
  20. ' fixed helvetica 15 font - would probably be better
  21. ' if it's font-adaptive, or sizes the window to fit.
  22. '
  23. REM $INCLUDE asl.bh ' HiSoft's ASL Requester support
  24. REM $INCLUDE graphics.bh
  25. REM $INCLUDE diskfont.bh
  26.  
  27. verstag$="$VER: TasRead 1.02 (26/4/99)"
  28.  
  29. CommandLine%=LEN(COMMAND$)
  30.  
  31. IF CommandLine%=0  
  32.  
  33.     LIBRARY OPEN "diskfont.library"
  34.     LIBRARY OPEN "graphics.library"
  35.     LIBRARY OPEN "asl.library"
  36.     DIM TextAttr%(4)
  37.     DIM frintags&(20) ' ASL Tag arrays
  38.     DIM frouttags&(20)
  39.   OutDrawer$="RAM:" ' Path defaults
  40.   InDrawer$="SP0:"
  41.   InName$=""
  42.   margin%=0
  43.   extraR%=(PEEKW(SYSTAB+2)-200)\2 ' Add to file requester
  44.   extra%=extraR%
  45.   IF extraR%>18 THEN extra%=18 ' Add to window is limited
  46. END IF
  47.  
  48. REPEAT outer_loop
  49.  
  50.     IF CommandLine%
  51.         ' we have a command line - try to parse it
  52.         
  53.         InFile$=COMMAND$
  54.         IF INSTR(InFile$,"?") THEN
  55.           PRINT "Fixed to variable length file converter ";ver$
  56.             PRINT "Example: TasREAD InFile OutFile"
  57.             SYSTEM
  58.         END IF
  59.         gap%=INSTR(InFile$," ")
  60.         gap1%=gap%
  61.  
  62.         REPEAT closeUp          
  63.           IF gap%=0 THEN EXIT closeUp
  64.           IF gap%>=LEN(InFile$) THEN gap%=0 : EXIT closeUp
  65.           IF MID$(Infile$,gap%+1,1)<"!"
  66.             gap%=gap%+1
  67.           ELSE
  68.             EXIT closeUp
  69.           END IF
  70.         END REPEAT closeUp
  71.  
  72.         IF gap%=0
  73.           OutFile$=InFile$+".ExTas"
  74.         ELSE
  75.           IF UCASE$(MID$(InFile$,gap%+1,2))="TO" AND MID$(InFile$,gap%+3,1)<"!"
  76.             OutFile$=MID$(InFile$,gap%+3,1024)
  77.           ELSE
  78.               OutFile$=MID$(InFile$,gap%+1,1024)
  79.           END IF
  80.           REPEAT tidy
  81.               IF LEFT$(OutFile$,1)<"!"
  82.                 OutFile$=MID$(OutFile$,2,1024)
  83.             ELSE
  84.                 EXIT tidy ' Controls and spaces stripped from start
  85.               END IF
  86.         END REPEAT tidy
  87.           InFile$=LEFT$(InFile$,gap1%-1) ' Keep up to first space
  88.         END IF
  89.         PRINT "Converting from ";Infile$;" TO ";Outfile$
  90.               
  91.     ELSE
  92.  
  93.       ' Use Workbench screen (assume 640x200) ' SCREEN 1,640,200,LOG2(2),4
  94.       WINDOW 1," TasRead by Simon N Goodwin, version " + MID$(verstag$,14,5), _
  95.         (60,2+extra%)-(560,198+extra%),2+4+16+256
  96.       WIDTH 72 ' Ensure text leaves room for a progress bar on the right
  97.  
  98.         REM Use a groovy Compugraphic fo(u)nt
  99.  
  100.         InitTextAttr TextAttr%(),"helvetica.font",15,0,0
  101.         font& = OpenDiskFont (VARPTR(TextAttr%(0)))
  102.         IF font&=0
  103.           PRINT "Oops - Helvetica 15 point font not found!"
  104.           PRINT "Tap something to use your system default."
  105.           MouseWait
  106.         ELSE
  107.             SetFont WINDOW (8), font&
  108.             COLOR 1,0,1
  109.         END IF
  110.  
  111.       CLS
  112.       PRINT
  113.     PRINT " This utility converts files in TasWord or SamScratch fixed-length"
  114.       PRINT " line format into Amiga OS, Unix and Qdos files of lines delimited"
  115.       PRINT " by Line Feed characters [CHR$(10)] so they can be read or edited."
  116.       PRINT
  117.       PRINT " Written in Amiga HiSoft BASIC 2 by Simon N Goodwin 2/1997-4/1999."
  118.       PRINT
  119.  
  120.       LINE (463,13)-(526,128),2,b
  121.       LINE (464,14)-(527,129),1,b
  122.  
  123.     ' No command line so use the ASL file requester (expects WB2 and up)
  124.         TAGLIST VARPTR(frintags&(0)),ASLFR_TitleText&,"Input file selector", _
  125.                 ASLFR_InitialFile&,InName$, _
  126.                 ASLFR_InitialDrawer&, InDrawer$, _
  127.                 ASLFR_InitialHeight&, 150+extraR%, _
  128.                 ASLFR_InitialLeftEdge&, 338, _
  129.                 ASLFR_InitialTopEdge&, 50+extraR%, _ 
  130.                 TAG_DONE&
  131.         fr&=AllocAslRequest&(ASL_FileRequest&,VARPTR(frintags&(0)))
  132.     
  133.         IF fr& THEN
  134.             IF AslRequest&(fr&,0) THEN
  135.             ' A file name was entered; build the full path
  136.                 InDrawer$=PEEK$(PEEKL(fr&+fr_Drawer%)): filename$=InDrawer$
  137.               IF RIGHT$(InDrawer$,1)<>":" THEN filename$=filename$+"/" 
  138.               InName$=PEEK$(PEEKL(fr&+fr_File%))
  139.                 filename$=filename$+InName$
  140.             ELSE
  141.               filename$=""        
  142.             END IF
  143.             FreeASlRequest fr&
  144.         InFile$=filename$
  145.         COLOR 1,3,1
  146.         PRINT PTAB(margin%);"Reading from ";InFile$
  147.         ELSE
  148.           REM No ASL - this currently fails at the OPEN LIBRARY
  149.         INPUT "      Enter TasWord filename  >";InFile$
  150.          END IF
  151.  
  152.       IF InFile$="" THEN EXIT outer_loop
  153.     
  154.       IF UCASE$(RIGHT$(InName$,4))=".TAS"
  155.         OutFile$=LEFT$(InName$,LEN(InName$)-4)+".ExTas"
  156.       ELSE
  157.         OutFile$=InName$+".ExTas"
  158.       END IF
  159.  
  160.         TAGLIST VARPTR(frouttags&(0)), _
  161.             ASLFR_TitleText&,"Output file selector", _
  162.                 ASLFR_InitialFile&, OutFile$, _
  163.                 ASLFR_InitialDrawer&, OutDrawer$, _
  164.                 ASLFR_InitialHeight&, 150+extraR%, _
  165.                 ASLFR_InitialLeftEdge&, 336, _
  166.                 ASLFR_InitialTopEdge&, 50+extraR%, _ 
  167.                 TAG_DONE&
  168.       fr&=AllocAslRequest&(ASL_FileRequest&,VARPTR(frouttags&(0)))
  169.       
  170.         IF fr& THEN
  171.             IF AslRequest&(fr&,0) THEN
  172.             ' A file name was entered; build the full path
  173.                 filename$=PEEK$(PEEKL(fr&+fr_Drawer%))
  174.               IF RIGHT$(filename$,1)<>":" THEN filename$=filename$+"/" 
  175.               filename$=filename$+PEEK$(PEEKL(fr&+fr_File%))
  176.             ELSE
  177.               filename$=""        
  178.             END IF
  179.             FreeASlRequest fr&
  180.         OutFile$=filename$
  181.         PRINT PTAB(margin%);"Writing to ";OutFile$
  182.         ELSE
  183.         INPUT " Enter destination filename  >";OutFile$
  184.       END IF
  185.       
  186.       IF OutFile$="" THEN EXIT outer_loop
  187.     
  188.         PRINT PTAB(margin%);"Converting...";
  189.     END IF ' Interactive        
  190.  
  191.     OPEN InFile$ FOR INPUT AS #4
  192.     
  193. ' Attempt to work out line width from file size
  194. ' This is not tested yet. Also character arrays
  195. ' should be regonised and specially treated.
  196.  
  197.   a$=INPUT$(12,#4)
  198.   IF LEFT$(a$,8)="PLUS3DOS"
  199.     a$=INPUT$(128-12,#4) ' Strip rest of 3 header    
  200.     Prefix%=64
  201.   ELSE
  202.     IF LEFT$(a$,4)="ZX82"
  203.       Prefix%=12
  204.     ELSE
  205.       PRINT "Sorry, ";Infile$;" is not a ZX82 format file."
  206.       MouseWait
  207.       EXIT outer_loop
  208.     END IF
  209.   END IF
  210.   length%=64
  211.   IF Prefix%=(LOF(4) MOD 85) THEN length%=85 ' Wide?
  212. ' IF Prefix%=(LOF(4) MOD 32) THEN length%=32 ' Narrow??
  213.  
  214.     OPEN Outfile$ FOR OUTPUT AS #5
  215.  
  216.     REPEAT paraLoop
  217.         IF EOF(4) THEN EXIT paraLoop
  218.         
  219.         IF LOC(4)+length%>LOF(4) THEN length%=LOF(4)-LOC(4)
  220.         
  221.         a$=INPUT$(length%,#4)
  222.         
  223.         IF a$=SPACE$(length%)
  224.           a$=""
  225.         ELSE
  226.           here%=length%
  227.           REPEAT trim
  228.             IF MID$(a$,here%,1)=" "
  229.               here%=here%-1
  230.             ELSE
  231.               a$=LEFT$(a$,here%)
  232.               EXIT trim
  233.             END IF
  234.           END REPEAT trim
  235.       END IF
  236.       
  237.         PRINT #5,a$
  238.       
  239.       IF CommandLine%=0
  240.         IF LOC(4)=LOF(4) THEN 
  241.           LINE (474,20)-(514,120),1,bf
  242.         ELSE 
  243.           LINE (474,20)-(514,20+LOC(4)*100\LOF(4)),1,bf
  244.         END IF
  245.       END IF
  246.       
  247.     END REPEAT paraLoop
  248.  
  249.     CLOSE #5
  250.     CLOSE #4
  251.         
  252.     IF CommandLine% THEN EXIT outer_loop
  253.     
  254.     PRINT "Done - tap to continue."; : MouseWait
  255.     
  256. END REPEAT outer_loop
  257.  
  258. SYSTEM ' Formerly STOP but no need for keypress
  259.  
  260. ' Amiga specific user-interface stuff follows
  261.  
  262. SUB InitTextAttr(T%(1),FontName$,BYVAL Height,BYVAL style,BYVAL flags)
  263.  
  264. POKEL VARPTR(T%(0))+ta_Name%,SADD(FontName$+CHR$(0))
  265. T%(ta_YSize%\2)=Height
  266. POKEB VARPTR(T%(0))+ta_Style%,style
  267. POKEB VARPTR(T%(0))+ta_Flags%,flags
  268.  
  269. END SUB
  270.  
  271. SUB MouseWait
  272.     LOCAL key$ ' No need to share here
  273.  
  274.     REPEAT debounce
  275.       IF MOUSE(0)=0 THEN EXIT debounce
  276.     END REPEAT debounce
  277.  
  278.     REPEAT poll
  279.       SLEEP : key$=INKEY$
  280.       IF MOUSE(0) THEN key$=CHR$(0)
  281.       IF LEN(key$) THEN EXIT poll 
  282.     END REPEAT poll
  283.  
  284. END SUB ' MouseWait
  285.  
  286.